<?php
namespace Admin\Controller;

class SxlController extends AdminController
{

  
    public function index()
    {
    	$name          = I('get.name');
        $map['status'] = array('egt', 0);
        if (is_numeric($name)) {
            $map['id|name'] = array(intval($name), array('like', '%' . $name . '%'), '_multi' => true);
        } else {
            $map['name'] = array('like', '%' . (string) $name . '%');
        }

        $res = $this->lists('attrkey', $map);
        $this->assign('res', $res);
        $this->display(); 
       
    }

    public function add()
    {   
          if (IS_GET) {
          	$a=I('get.');
            // dump($a);
            $this->display();
           } else {

           $b=I('post.');
           // dump($b);die;
           $data=M('attrkey')->add($b);
           // dump($data);die;
            if ($data) {
                $this->success('添加属性成功', U('index'));
            } else {
                $this->error('添加属性失败');
            }
        
    }
   
    }


    public function update()
    {
            if (IS_GET) {
            $id=I('get.id');
            $res=M('attrkey')->where(['id'=>$id])->select();
            $this->assign('res1',$res);
            $this->display();
         } else {
         	$post=I('post.');
         	// dump($post);die;
         	$data=M('attrkey')->where(['id' => I('post.ooid')])->save($post);
            if ($data) {
               
                $this->success('编辑成功', U('index'));
            } else {
                $this->error('编辑失败');
            }
        }
  
    }


    public function del()
    {
    }

    public function changeStatus($method = null)
    {
        $id = array_unique((array) I('id', 0));

        $id = is_array($id) ? implode(',', $id) : $id;
        if (empty($id)) {
            $this->error('请选择要操作的数据!');
        }
        $map['id'] = array('in', $id);
        switch (strtolower($method)) {
            case 'del':
                M('attrkey')->where($map)->delete();
                $this->success('删除成功');
                break;
            default:
                $this->error('参数非法');
        }
    }
}